; (function () {
	var Edit = window.wangEditor
	var editor = new Edit('#editor')
	editor.customConfig.zIndex = 100
	editor.customConfig.uploadImgServer = uploadUrl
	editor.customConfig.uploadFileName = 'file'
	editor.customConfig.customAlert = function (info) { }
	editor.customConfig.uploadImgHooks = {
		// 如果服务器端返回的不是 {errno:0, data: [...]} 这种格式，可使用该配置
		// （但是，服务器端返回的必须是一个 JSON 格式字符串！！！否则会报错）
		customInsert: function (insertImg, result, editor) {
			// 图片上传并返回结果，自定义插入图片的事件（而不是编辑器自动插入图片！！！）
			// insertImg 是插入图片的函数，editor 是编辑器对象，result 是服务器端返回的结果
			// 举例：假如上传图片成功后，服务器端返回的是 {url:'....'} 这种格式，即可这样插入图片：
			var url = result.url
			insertImg(url)
		}
	}
	// editor.txt.html()  读取内容
	// editor.txt.html('<p>用 JS 设置的内容</p>')   设置内容

	new Vue({
		el: '#jwk-work-add-edit',
		data() {
			return {
				id: hlUrlUtil.GetQueryString('id'),
				addItem: {
					"name": "",
					"main_pic_name": [],
					"main_pic_url": [],
					"banner_pic_names": [],
					"banner_pic_urls": [],
					"acreage": "",
					"floor_height": "",
					"apartment_layout_code": [],
					"apartment_layout": "",
					"apartment_decoration_code": [],
					"apartment_decoration": "",
					"contact_phone_num": "",
					"rewards": "",
					"rent_price": "",
					"rent_price_units_code":[],
					"property_fee": "",
					"park_id": "",
				},
				decorate: [], //装修下拉列表
				model:[],//户型下拉列表
				rentList:[],//租金下拉列表
				picType: '',  //图片上传类型
				parkInfo: {
					name: '',
					city: '',
					district: '',
					address: '',
					trafficInfo: '',
					parkingPrice: '',
					location: "116.397399,39.909209"
				}, //园区信息
				parkList: [],
				selectMatingCode: [],
				selectMatingList:[],

			}
		},
		methods: {
			// 获取办公租赁详情
			getDetail() {
				var that = this;
				hlhttp.get({
					url: 'jwk/biz_rent_office',
					data: {
						id: this.id
					},
					success: data => {
						that.addItem = {
							"name": data.name,
							"main_pic_name": [data.mainPicName],
							"main_pic_url": [data.mainPicUrl],
							"banner_pic_names": [data.bannerPicNames],
							"banner_pic_urls": [data.bannerPicUrls],
							"acreage": data.acreage + '',
							"floor_height": data.floorHeight + '',
							"apartment_layout_code": [data.apartmentLayoutCode],
							"apartment_layout": data.apartmentLayout + '',
							"apartment_decoration_code": [data.apartmentDecorationCode],
							"apartment_decoration": data.apartmentDecoration + '',
							"contact_phone_num": data.contactPhoneNum + '',
							"rewards": data.rewards + '',
							"rent_price": data.rentPrice + '',
							"rent_price_units_code":[data.rentPriceUnitsCode],
							"property_fee": data.propertyFee + '',
							"park_id": data.parkId + '',
						}
						that.parkInfo = data.parkInfo
						editor.txt.html(data.detailIntro)
						that.mapGaoge()
					}
				})
			},
			// 获取租金字典
			getRent(){
				var that = this;
				hlhttp.get({
					url: 'configure/dict',
					data: { 'module_code': 'CSTM_JWK', 'config_name': 'CSTM_JWK_PARK_RENT_PRICE_UNITS' },
					success: data => {
						data.map(item => {
							item.name = item.dictName
							item.code = item.dictCode
						})
						that.rentList = data
					}
				})
			},
			// 获取户型
			getModel(){
				var that = this;
				hlhttp.get({
					url: 'configure/dict',
					data: { 'module_code': 'CSTM_JWK', 'config_name': 'CSTM_JWK_APARTMENT_LAYOUT' },
					success: data => {
						data.map(item => {
							item.name = item.dictName
							item.code = item.dictCode
						})
						that.model = data
					}
				})
			},
			// 选择户型
			selectModel(val){
				this.addItem.apartment_layout = val[0].name
				console.log(this.addItem.apartment_layout)
			},
			//获取装修
			getDecorate() {
				var that = this;
				hlhttp.get({
					url: 'unit/decoration_types',
					data: { 'module_code': 'CSTM_JWK', 'config_name': 'CSTM_JWK_APARTMENT_DECORATION' },
					success: data => {
						data.map(item => {
							item.name = item.memo
						})
						that.decorate = data
					}
				})
			},
			// 选择装修
			selectDecorate(val) {
				this.addItem.apartment_decoration = val[0].name
			},
			//图片上传click()触发
			picUp(val) {
				this.picType = val
				$('.picButton').trigger('click')
			},
			picToClick() {
				var that = this
				imgupload('.picButton', uploadUrl, (res) => {
					if (that.picType == 'F') {
						that.addItem.main_pic_name.push(res.json.name)
						that.addItem.main_pic_url.push(res.json.url)
					} else {
						that.addItem.banner_pic_names.push(res.json.name)
						that.addItem.banner_pic_urls.push(res.json.url)
					}
				})
			},
			// 删除图片
			delPic(index, type) {
				if (type == 'F') {
					this.addItem.main_pic_name.splice(index, 1)
					this.addItem.main_pic_url.splice(index, 1)
				} else {
					this.addItem.banner_pic_names.splice(index, 1)
					this.addItem.banner_pic_urls.splice(index, 1)
				}
			},

			// 获取园区数据
			getParkData(val, callback) {
				console.log(val)
				var that = this;
				hlhttp.get({
					url: 'jwk/park_info/_search',
					data: {
						keyword: val || '#'
					},
					success: data => {
						callback(data)
					}
				})
			},
			selectParkId(val) {
				this.parkInfo = val
				this.addItem.park_id = val.id
				this.mapGaoge()
			},

			// 检测是否填写完整
			checkSumit() {
				if (!this.addItem.name) {
					hl.toast('请输入房源信息')
					return false
				}
				if (!this.addItem.main_pic_name.length) {
					hl.toast('请上传房源头图')
					return false
				}
				if (!this.addItem.banner_pic_names.length) {
					hl.toast('请上传内页轮播')
					return false
				}
				if (!this.addItem.acreage) {
					hl.toast('请填写面积')
					return false
				}
				if (!this.addItem.floor_height) {
					hl.toast('请填写层高')
					return false
				}
				if (!this.addItem.apartment_layout_code.length) {
					hl.toast('请选择户型')
					return false
				}
				if (!this.addItem.apartment_decoration_code.length) {
					hl.toast('请选择装修')
					return false
				}
				if (!this.addItem.contact_phone_num) {
					hl.toast('请填写联系电话')
					return false
				}
				if (!this.addItem.rewards) {
					hl.toast('请填写赏金')
					return false
				}
				if (!this.addItem.rent_price) {
					hl.toast('请填写租金')
					return false
				}
				if (!this.addItem.rent_price_units_code.length) {
					hl.toast('请选择租金单位')
					return false
				}
				if (!this.addItem.property_fee) {
					hl.toast('请填写物业费')
					return false
				}
				if (!this.addItem.park_id) {
					hl.toast('请选择园区')
					return false
				}
				return true
			},

			// 保存
			saveSumit() {
				if (!this.checkSumit()) return
				let data = this.addItem
				data.main_pic_name = data.main_pic_name + ''
				data.main_pic_url = data.main_pic_url + ''
				data.banner_pic_names = data.banner_pic_names + ''
				data.banner_pic_urls = data.banner_pic_urls + ''
				data.apartment_decoration_code = data.apartment_decoration_code + ''
				data.apartment_layout_code = data.apartment_layout_code + ''
				data.rent_price_units_code = data.rent_price_units_code + ''
				data.detail_intro = editor.txt.html()
				this.parkInfo.parkFacilityList = this.selectMatingList
				data.parkInfo = JSON.stringify(this.parkInfo)
				console.log(data)
				var that = this;
				if (this.id) {
					data.id = this.id
					hlhttp.put({
						url: 'jwk/biz_rent_office',
						data: data,
						success: data => {
							hlUrlUtil.goTo('jwkList', { ddtab: true })
						}
					})
				} else {
					hlhttp.post({
						url: 'jwk/biz_rent_office',
						data: data,
						success: data => {
							hlUrlUtil.goTo('jwkList', { ddtab: true })
						}
					})
				}

			},



			// 地图
			//map
			mapGaoge() {
				let center = this.parkInfo.location.split(',')
				let map = new AMap.Map('mapGaode', {
					resizeEnable: true,
					center: center,
					zoom: 14
				});
				var marker = new AMap.Marker({
					position: new AMap.LngLat(map.getCenter().lng, map.getCenter().lat),
					icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
					offset: new AMap.Pixel(-10, -20)
				});
				map.add(marker);
			},


		},
		mounted() {
			editor.create()
			this.getDecorate()
			this.getModel()
			this.picToClick();
			this.getRent();
			if (this.id) {
				this.getDetail()
			} else {
				this.mapGaoge()
			}
		}
	})
}())
